audio and video playing
authorAsbjørn Sloth Tønnesen <asbjorn@ahead.com>
Fri, 16 Apr 2010 12:16:32 +0000 (12:16 +0000)
committerAsbjørn Sloth Tønnesen <asbjorn@ahead.com>
Fri, 16 Apr 2010 12:16:32 +0000 (12:16 +0000)
src/audioplayer.py [new file with mode: 0644]
src/mediaplayer.py [new file with mode: 0644]
src/talkcutter.py
src/videoplayer.py

diff --git a/src/audioplayer.py b/src/audioplayer.py
new file mode 100644 (file)
index 0000000..aac7bdf
--- /dev/null
@@ -0,0 +1,21 @@
+import os
+import gst, gtk, gobject
+import sys
+import pygtk
+import gtk
+import gtk.glade
+from mediaplayer import mediaplayer
+
+class audioplayer(mediaplayer):
+    def __init__( self, parent ):
+        self.parent = parent
+        self.wTree = parent.wTree
+
+        self.spinner = self.wTree.get_widget('audio_spin')
+        self.seeker = self.wTree.get_widget('audio_seeker')
+        self.label = self.wTree.get_widget('audio_label')
+
+        super(audioplayer, self).__init__()
+
+
+
diff --git a/src/mediaplayer.py b/src/mediaplayer.py
new file mode 100644 (file)
index 0000000..b2741b0
--- /dev/null
@@ -0,0 +1,94 @@
+import os
+import gst, gtk, gobject
+import sys
+import pygtk
+import gtk
+import gtk.glade
+
+class mediaplayer(object):
+    def __init__( self ):
+        self.playbin = gst.element_factory_make('playbin2')
+
+        self.bus = self.playbin.get_bus()
+        self.bus.add_signal_watch()
+        self.bus.connect("message::eos", self.on_finish)
+
+        self.spinner.set_range(0, 100)
+        self.spinner.set_increments(1, 10)
+        self.spinner.connect('change-value', self.on_seeker_change)
+
+        self.seeker.set_range(0, 100)
+        self.seeker.set_increments(1, 10)
+        self.seeker.connect('change-value', self.on_seeker_change)
+        self.seeker.connect('button-press-event', self.on_button_press)
+        self.seeker.connect('button-release-event', self.on_button_release)
+
+        self.is_playing = False
+        self.known_range = False
+
+    def play(self, uri):
+        self.playbin.set_property('uri', uri)
+        self.playbin.set_state(gst.STATE_PLAYING)
+        self.label.label = 'f';
+        gobject.timeout_add(100, self.update_slider)
+        self.is_playing = True
+        self.known_range = False
+
+    def on_finish(self, bus, message):
+        self.playbin.set_state(gst.STATE_PAUSED);
+        self.spinner.set_value(0);
+        self.seeker.set_value(0);
+
+    def on_video_realized(self, sender):
+        self.sink.set_xwindow_id(self.drawingarea.window.xid)
+
+    def update_slider(self):
+        if not self.is_playing:
+            return False # cancel timeout
+
+        try:
+            if not self.known_range:
+                duration_nanosecs, format = self.playbin.query_duration(gst.FORMAT_TIME)
+                if duration_nanosecs > 0:
+                  duration_secs = float(duration_nanosecs) / gst.SECOND
+                  print duration_secs
+                  self.seeker.set_range(0, duration_secs)
+                  self.spinner.set_range(0, duration_secs)
+                  self.known_range = True
+                  print "Duration: %f" % (duration_secs) 
+
+            nanosecs, format = self.playbin.query_position(gst.FORMAT_TIME)
+
+            # block seek handler so we don't seek when we set_value()
+            self.seeker.handler_block_by_func(self.on_seeker_change)
+            self.spinner.handler_block_by_func(self.on_seeker_change)
+
+            value = float(nanosecs) / gst.SECOND;
+
+            #print "Trigger: %f" % (value) 
+
+            self.seeker.set_value(value)
+            self.spinner.set_text("%f" %(value))
+
+            self.seeker.handler_unblock_by_func(self.on_seeker_change)
+            self.spinner.handler_unblock_by_func(self.on_seeker_change)
+
+        except gst.QueryError:
+            # pipeline must not be ready and does not know position
+            pass
+
+        return True # continue calling every 30 milliseconds
+
+
+    def on_seeker_change(self, element, a, b):
+        print 'on_seeker_change'
+        seek_time_secs = element.get_value()
+        self.playbin.seek_simple(gst.FORMAT_TIME, gst.SEEK_FLAG_FLUSH | gst.SEEK_FLAG_KEY_UNIT, seek_time_secs * gst.SECOND)
+
+    def on_button_press(self, element, a):
+        self.playbin.set_state(gst.STATE_PAUSED);
+
+    def on_button_release(self, element, a):
+        self.playbin.set_state(gst.STATE_PLAYING)
+
+
index bf91923..103a70a 100755 (executable)
@@ -3,6 +3,7 @@ import os
 import gst, gtk, gobject
 import sys
 from videoplayer import videoplayer
+from audioplayer import audioplayer
 try:
     import pygtk
     pygtk.require("2.0")
@@ -34,6 +35,9 @@ class TalkCutter:
 
         print self.drawingarea
 
+        self.audio = audioplayer(self)
+        self.audio.play('file:///mnt/dl/dkuug/video/osd10/dan/dan.wav');
+
         self.video = videoplayer(self)
         self.video.play('file:///mnt/dl/dkuug/video/osd10/dan/dan.dv')
 
index 04f0f80..0d88a22 100644 (file)
@@ -4,79 +4,32 @@ import sys
 import pygtk
 import gtk
 import gtk.glade
+from mediaplayer import mediaplayer
 
-class videoplayer:
+class videoplayer(mediaplayer):
+    
     def __init__( self, parent ):
         self.parent = parent
         self.wTree = parent.wTree
 
-        self.playbin = gst.element_factory_make('playbin2')
+        self.spinner = self.wTree.get_widget('video_spin')
+        self.seeker = self.wTree.get_widget('video_seeker')
+        self.label = self.wTree.get_widget('video_label')
+        self.drawingarea = self.wTree.get_widget('video')
+
+        super(videoplayer, self).__init__()
 
         self.sink = gst.element_factory_make('xvimagesink')
         self.sink.set_property('force-aspect-ratio', True)
         self.playbin.set_property('video-sink', self.sink)
 
-        self.bus = self.playbin.get_bus()
-        self.bus.add_signal_watch()
-        self.bus.connect("message::eos", self.on_finish)
+        audiosink = gst.element_factory_make('fakesink')
+        self.playbin.set_property('audio-sink', audiosink)
 
-        self.drawingarea = self.wTree.get_widget('video')
         self.drawingarea.connect('realize', self.on_video_realized)
 
-        self.spinner = self.wTree.get_widget('video_spin')
-        #self.spinner.connect('change-value', self.on_)
-
-        self.seeker = self.wTree.get_widget('video_seeker')
-        self.seeker.set_range(0, 100)
-        self.seeker.set_increments(1, 10)
-        self.seeker.connect('change-value', self.on_seeker_change)
-
-        self.label = self.wTree.get_widget('video_label')
-
-        self.is_playing = False
-
-    def play(self, uri):
-        self.playbin.set_property('uri', uri)
-        self.playbin.set_state(gst.STATE_PLAYING)
-        self.label.label = 'f';
-        gobject.timeout_add(100, self.update_slider)
-        self.is_playing = True
-
-    def on_finish(self, bus, message):
-        self.playbin.set_state(gst.STATE_PAUSED);
-        self.slider.set_value(0);
 
     def on_video_realized(self, sender):
         self.sink.set_xwindow_id(self.drawingarea.window.xid)
 
 
-    def update_slider(self):
-        if not self.is_playing:
-            return False # cancel timeout
-
-        try:
-            nanosecs, format = self.playbin.query_position(gst.FORMAT_TIME)
-            duration_nanosecs, format = self.playbin.query_duration(gst.FORMAT_TIME)
-
-            # block seek handler so we don't seek when we set_value()
-            self.seeker.handler_block_by_func(self.on_seeker_change)
-
-            self.seeker.set_range(0, float(duration_nanosecs) / gst.SECOND)
-            self.seeker.set_value(float(nanosecs) / gst.SECOND)
-
-            self.seeker.handler_unblock_by_func(self.on_seeker_change)
-
-        except gst.QueryError:
-            # pipeline must not be ready and does not know position
-         pass
-
-        return True # continue calling every 30 milliseconds
-
-
-    def on_seeker_change(self, slider, a, b):
-        print 'on_seeker_change'
-        seek_time_secs = slider.get_value()
-        self.playbin.seek_simple(gst.FORMAT_TIME, gst.SEEK_FLAG_FLUSH | gst.SEEK_FLAG_KEY_UNIT, seek_time_secs * gst.SECOND)
-
-
-